package com.isale.generator;


import com.isale.generator.bean.Config;
import com.isale.generator.bean.TableInfo;
import com.isale.generator.db.MySQLGenerator;
import com.isale.generator.output.VelocityOutput;
import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by bjs on 2016/6/20.
 */
public class ExceMain {
    public static void main(String args[]) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"});


        List<String> tableList = new ArrayList<String>();


        tableList.add("sys_user");
        tableList.add("sys_role");
        tableList.add("sys_resource");
        tableList.add("sys_organization");


        for (String tableName : tableList) {
            doOneTable(tableName);
        }
    }

    private static void doOneTable(String tableName) {


        TableInfo tableInfo = MySQLGenerator.getTableInfo(tableName);
        MySQLGenerator.getColumnList(tableInfo);


        Config config = new Config();

        config.setAuthor("bjs");
        config.setCreateGeneratorTime(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));

        config.setEntityPkg("com.isale.model.db");
        config.setDaoPkg("com.isale.dao");
        config.setServicePkg("com.isale.service");
        config.setControllerPkg("com.isale.web.sys.controller");
        config.setVmTemplatePath("sys");
        config.setUrlPrefix("");


//        config.setOutputPath("/Users/bain.wang/gen/");


//        config.setEntityOutputPath("D:\\subang\\ideaprojects\\isale\\src\\main\\java\\com\\isale\\model\\db\\");
//        config.setDaoOutputPath("D:\\subang\\ideaprojects\\isale\\src\\main\\java\\com\\isale\\dao\\");
//        config.setServiceOutputPath("D:\\subang\\ideaprojects\\isale\\src\\main\\java\\com\\isale\\service\\");
//        config.setControllerOutputPath("D:\\subang\\ideaprojects\\isale\\src\\main\\java\\com\\isale\\web\\sys\\controller\\");
//        config.setVmOutputPath("D:\\subang\\ideaprojects\\isale\\src\\main\\webapp\\WEB-INF\\velocity\\sys\\");
//        config.setJsOutputPath("D:\\subang\\ideaprojects\\isale\\src\\main\\webapp\\statics\\pages\\sys\\");

 config.setEntityOutputPath("D:\\subang\\ideaprojects\\isale\\src\\main\\java\\com\\isale\\model\\db\\");
        config.setDaoOutputPath("D:\\subang\\ideaprojects\\isale\\src\\main\\java\\com\\isale\\dao\\");
        config.setServiceOutputPath("D:\\subang\\ideaprojects\\isale\\src\\main\\java\\com\\isale\\service\\");
        config.setControllerOutputPath("D:\\subang\\ideaprojects\\isale\\src\\main\\java\\com\\isale\\web\\sys\\controller\\");
        config.setVmOutputPath("D:\\subang\\ideaprojects\\isale\\src\\main\\webapp\\WEB-INF\\velocity\\sys\\");
        config.setJsOutputPath("D:\\subang\\ideaprojects\\isale\\src\\main\\webapp\\statics\\pages\\sys\\");


        VelocityOutput.execute(tableInfo, config);

    }
}
